import { defineStore } from "pinia";
import { getBanner, getNew, getHot, getBrand, getGoods, getSpecial } from "@/api/home";
import { BannerItem, GoodsItem, HotItem, BrandItem, HomeProduct, Special } from "@/types/data";

export default defineStore('home', {
  state () {
    return {
      bannerList: [] as BannerItem[],
      goodsList: [] as GoodsItem[],
      hotList: [] as HotItem[],
      brandList: [] as BrandItem[],
      productList: [] as HomeProduct[],
      specialList: [] as Special[],
    }
  },
  actions: {
    // 获取首页轮播图数据 
    async getBannerList () {
      const res = await getBanner()
      this.bannerList = res.data.result
    },
    // 获取新鲜好物
    async getNewList () {
      const res = await getNew()
      this.goodsList = res.data.result
    },

    // 获取人气推荐
    async getHotList () {
      const res = await getHot()
      this.hotList = res.data.result
    },

    // 获取热门品牌
    async getBrandList () {
      const res = await getBrand()
      this.brandList = res.data.result
    },

    // 获取产品列表
    async getProductList () {
      const res = await getGoods()
      this.productList = res.data.result
    },


    // 获取最新专题
    async getSpecialList () {
      const res = await getSpecial()
      this.specialList = res.data.result
    }
  }
})